package com.jielin.handling.controller.policeplatform;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.jielin.handling.Annotation.MyPower;
import com.jielin.handling.bean.AppResult;
import com.jielin.handling.db.InquestionsMapper;
import com.jielin.handling.entity.alarmlog.AlarmLog;
import com.jielin.handling.entity.material.MaterialType;
import com.jielin.handling.entity.material.MaterialTypeDocument;
import com.jielin.handling.entity.policeplatform.CabinetVo;
import com.jielin.handling.entity.policeplatform.DateMount;
import com.jielin.handling.entity.policeplatform.Organization;
import com.jielin.handling.entity.unit.OrganizationVo;
import com.jielin.handling.entity.unit.UnitInfo;
import com.jielin.handling.entity.vo.*;
import com.jielin.handling.exception.ResultEnum;
import com.jielin.handling.page.DataGrid;
import com.jielin.handling.redis.RedisKey;
import com.jielin.handling.redis.RedisTemplateX;
import com.jielin.handling.service.material.MaterialTypeDocumentService;
import com.jielin.handling.service.material.MaterialTypeService;
import com.jielin.handling.service.policeplatform.PolicePlatformService;
import com.jielin.handling.service.unit.UnitService;
import com.jielin.handling.util.ConstantUtil;
import com.jielin.handling.util.DateUtil;
import com.jielin.handling.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.protocol.HTTP;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.*;

/**
 * @author chenzhang
 * @date 2019/5/7 - 19:15
 */
@CrossOrigin
@RestController
//@Controller
@RequestMapping("/policePlatform/")
@Slf4j
@MyPower(name = "警综数据操作平台", url = "/policePlatform")
public class PolicePlatformController {

    @Autowired
    PolicePlatformService platformService;
    @Autowired
    private RedisTemplateX redisTemplateX;
    @Autowired
    UnitService unitService;
    @Autowired
    private InquestionsMapper inquestionsMapper;
    @Autowired
    MaterialTypeDocumentService materialTypeDocumentService;
    @Autowired
    MaterialTypeService materialTypeService;

    /**
     * 查询所有单位编号
     *
     * @return
     */
    @ResponseBody
    @MyPower(name = "查询所有单位编号", url = "/selectUnicode")
    @RequestMapping("selectUnicode")
    public AppResult selectUnicode() {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        List<String> list = platformService.selectUnicode();
        date.put("list", list);
        appResult.setCode(200);
        appResult.setMsg("查询所有单位编号成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 根据单位编号查询近三年每月的案件数量
     *
     * @param unitInfo 单位编号
     * @return
     */
    @MyPower(name = "根据单位编号查询近三年每月的案件数量", url = "/findCaseCountByUnitCode")
    @ResponseBody
    @RequestMapping("findCaseCountByUnitCode")
    public AppResult findCaseCountByUnitCode(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCode())) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(data);
            return result;
        }
        Map<String, List<Integer[]>> caseStatus = platformService.findCaseCountByUnitCode(unitInfo.getUnitCode().split(","));
        data.put("title", caseStatus == null ? null : caseStatus.get("title"));
        data.put("value", caseStatus == null ? null : caseStatus.get("value"));
        result.setCode(200);
        result.setMsg("根据单位编号查询近三年每月的案件数量成功!");
        result.setData(data);
        return result;
    }

    @MyPower(name = "查询近三年完结案件的趋势分析", url = "/findfinishedCase", isPublic = true)
    @RequestMapping("/findfinishedCase")
    public AppResult findfinishedCase(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject object = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(object);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(handleUnitCode)) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(handleUnitCode);
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }
            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");
            }
        }
        Map<String, Object> one = platformService.findBeforeYearsCase(array);
        Map<String, Object> two = platformService.findLastYearsCase(array);
        Map<String, Object> three = platformService.findThisYearsCase(array);
        object.put("one", one);
        object.put("two", two);
        object.put("three", three);
        result.setCode(200);
        result.setMsg("查询近三年完结案件趋势成功");
        result.setData(object);
        return result;
    }

    @MyPower(name = "近三年审核完成案件数的", url = "/findThreeYearsEndCase", isPublic = true)
    @RequestMapping("/findThreeYearsEndCase")
    public AppResult findThreeYearsEndCase(@RequestBody JSONObject jsonObject) {
        AppResult result = new AppResult();
        JSONObject jsonData = new JSONObject();
        Map<String, Object> threeYearsEndCase = platformService.findThreeYearsEndCase(jsonObject.getString("handleUnitCode"));

        jsonData.put("data", threeYearsEndCase);
        result.setCode(200);
        result.setMsg("查询近三年审核案件信息成功");
        result.setData(jsonData);

        return result;
    }

    /**
     * 根据单位编号查询审核完成案件数
     *
     * @param unitInfo 单位编号逗号分隔
     * @return
     */
    @MyPower(name = "根据单位编号查询审核完成案件数", url = "/findPassCaseCountByUnitCode")
    @ResponseBody
    @RequestMapping("findPassCaseCountByUnitCode")
    public AppResult findPassCaseCountByUnitCode(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(data);
            return result;
        }
        Map<String, List<Object>> caseStatus = platformService.findPassCaseCountByUnitCode(unitInfo.getUnitCodes().split(","), unitInfo.getStatus());
        data.put("title", caseStatus == null ? null : caseStatus.get("title"));
        data.put("value", caseStatus == null ? null : caseStatus.get("value"));
        result.setCode(200);
        result.setMsg("根据单位编号查询审核完成案件数成功!");
        result.setData(data);
        return result;
    }

    /**
     * 根据单位编号查询卷宗出入库统计
     *
     * @param unitInfo 单位编号
     * @return
     */
    @MyPower(name = "卷宗出入库统计", url = "/findMaterialCountByUnitCode")
    @ResponseBody
    @RequestMapping("findMaterialCountByUnitCode")
    public AppResult findMaterialCountByUnitCode(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(data);
            return result;
        }
        Map<String, List<Object>> caseStatus = platformService.findMaterialCountByUnitCode(unitInfo.getUnitCodes().split(","));
        data.put("title", caseStatus == null ? null : caseStatus.get("title"));
        data.put("value", caseStatus == null ? null : caseStatus.get("value"));
        result.setCode(200);
        result.setMsg("根据单位编号查询卷宗出入库统计成功!");
        result.setData(data);
        return result;
    }

    /**
     * 根据单位编号统计各个单位的卷宗
     *
     * @param unitInfo 单位编号
     * @return
     */
    @MyPower(name = "单位列表卷宗出入库统计", url = "/findMaterialCountByUnitCodeAndLibraryStatus")
    @ResponseBody
    @RequestMapping("findMaterialCountByUnitCodeAndLibraryStatus")
    public AppResult findMaterialCountByUnitCodeAndLibraryStatus(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        List<CabinetVo> list = platformService.findListMaterialCountByUnitCode(unitInfo.getUnitCodes().split(","));
        // 查询是否有子单位
        list.stream().forEach(item -> {
            item.setIsHaveChildUnit(unitService.findChildUnitNumById(item.getOrganizationId()));
        });
        date.put("value", list);
        result.setCode(200);
        result.setMsg("根据单位编号查询卷宗出入库统计成功!");
        result.setData(date);
        return result;
    }

    /**
     * 根据单位编号查询此单位接处警数量
     *
     * @param
     * @return
     */
    @MyPower(name = "根据单位编号查询此单位接处警数量", url = "/findCaseAccepptHandle")
    @ResponseBody
    @RequestMapping("findCaseAccepptHandle")
    public AppResult findCaseAccepptHandle(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        List<Map> map = platformService.findCaseAccepptHandle(unitInfo.getUnitCodes().split(","));
        date.put("list", map);
        appResult.setCode(200);
        appResult.setMsg("查询单位接处警数量成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 查询某些单位下嫌疑人数量和男女各总人数
     *
     * @param unitInfo 单位编号
     * @return
     */
    @MyPower(name = "查询某些单位下嫌疑人数量和男女各总人数", url = "/selectManAndWoMan")
    @ResponseBody
    @RequestMapping("selectManAndWoMan")
    public AppResult selectManAndWoMan(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount dateMount = platformService.selectManAndWoMan(unitInfo.getUnitCodes().split(","));
        date.put("dateMount", dateMount);
        appResult.setCode(200);
        appResult.setMsg("查询下级单位案件状态统计成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 根据单位编号查询下级单位案件状态统计
     *
     * @param unitInfo 单位编号
     * @return
     */
    @MyPower(name = "根据单位编号查询下级单位案件状态统计", url = "/findCaseStatusNum")
    @ResponseBody
    @RequestMapping("findCaseStatusNum")
    public AppResult findCaseStatusNum(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount caseStatus = platformService.findCaseStatusNum(unitInfo.getUnitCodes().split(","));
        date.put("list", caseStatus);
        appResult.setCode(200);
        appResult.setMsg("查询下级单位案件状态统计成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 当日办案区人数
     *
     * @param unitInfo
     * @return
     */
    @MyPower(name = "当日办案区人数", url = "/findToDayNum")
    @ResponseBody
    @RequestMapping("findToDayNum")
    public AppResult findToDayNum(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount dateMount = platformService.findToDayNum(unitInfo.getUnitCodes().split(","));
        date.put("list", dateMount);
        appResult.setCode(200);
        appResult.setMsg("查询当日办案区人数成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 查询每天和每周人数上涨比例
     *
     * @param unitInfo
     * @return
     */
    @MyPower(name = "查询每天和每周人数上涨比例", url = "/getProportion")
    @ResponseBody
    @RequestMapping("getProportion")
    public AppResult getProportion(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount vo = platformService.getProportion(unitInfo.getUnitCodes().split(","));
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("查询每天和每周人数上涨比例成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 正在使用审讯室
     *
     * @param unitInfo 单位编号集合
     * @return
     */
    @MyPower(name = "正在使用审讯室", url = "/selectRoomInUse")
    @ResponseBody
    @RequestMapping("selectRoomInUse")
    public AppResult selectRoomInUse(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        //String[] unitCodeS={"438200","420502000111"};
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount vo = platformService.selectRoomInUse(unitInfo.getUnitCodes().split(","));
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("查询正在使用审讯室成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 超时人数统计
     *
     * @param unitCodes(废弃接口)
     * @return
     */
//    @MyPower(name = "超时人数统计", url = "/selectOvertimeMan")
    @RequestMapping("selectOvertimeMan")
    public AppResult selectOvertimeMan(String[] unitCodes) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        //String[] unitCodeS={"438200","420502000111"};
        DateMount vo = platformService.selectOvertimeMan(unitCodes);
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("查询正在使用审讯室成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 等待审讯人数统计
     *
     * @param unitInfo
     * @return
     */
    @MyPower(name = "等待审讯人数统计", url = "/selectAwaitingTrial")
    @ResponseBody
    @RequestMapping("selectAwaitingTrial")
    public AppResult selectAwaitingTrial(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        //String[] unitCodeS={"0"};
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount vo = platformService.selectAwaitingTrial(unitInfo.getUnitCodes().split(","));
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("查询等待审讯人数统计成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 案件类型统计
     *
     * @return
     */
    @MyPower(name = "案件类型统计", url = "/caseStatistics", isPublic = true)
    @ResponseBody
    @RequestMapping("caseStatistics")
    public AppResult caseStatistics(@RequestBody UnitInfo unitInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        //String[] unitCodeS={"438200"};
        if (StringUtil.isEmpty(unitInfo.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        DateMount vo = platformService.caseStatistics(unitInfo.getUnitCodes().split(","));
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("查询案件类型统计成功");
        appResult.setData(date);
        return appResult;
    }

    @MyPower(name = "依次查询每个单位告警提醒", url = "/selectAll", isPublic = true)
    @ResponseBody
    @RequestMapping("selectAll")
    public AppResult selectAll(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        String pageNum = queryCondition.getString("pageNum");
        String pageSize = queryCondition.getString("pageSize");
        log.info("user query...");
        //查询条件+分页
        WarningVo warningVo = new WarningVo();
        warningVo.setQueryCondition(queryCondition);
        warningVo.setPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        if (StringUtil.isEmpty(warningVo.getUnitCodes())) {
            data.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(data);
            return appResult;
        }

        List<AlarmLog> orderList = platformService.selectAll(warningVo);
        PageInfo<AlarmLog> pageInfo = new PageInfo<AlarmLog>(orderList);
        DataGrid dataGrid = new DataGrid(pageInfo.getTotal(), pageInfo.getList());
        data.put("datagrid", dataGrid);
        appResult.setCode(200);
        appResult.setMsg("查询成功");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "查询某个单位所有告警提醒", url = "/selectAllByUnitcode")
    @ResponseBody
    @RequestMapping("selectAllByUnitcode")
    public AppResult selectAllByUnitcode(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        int pageNum = queryCondition.getIntValue("pageNum");
        int pageSize = queryCondition.getIntValue("pageSize");
        WarningVo warningVo = new WarningVo();
        warningVo.setQueryCondition(queryCondition);
        warningVo.setPage(pageNum, pageSize);
        List<AlarmLog> orderList = platformService.selectAllByUnitcode(warningVo);
        PageInfo<AlarmLog> pageInfo = new PageInfo<>(orderList);
        DataGrid dataGrid = new DataGrid(pageInfo.getTotal(), pageInfo.getList());
        data.put("datagrid", dataGrid);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "更新告警提醒是否已读", url = "/updateWarning", isPublic = true)
    @ResponseBody
    @RequestMapping("updateWarning")
    public AppResult updateWarning(String id) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        int value = platformService.updateWarning(id);
        if (value > 0) {
            data.put("value", 1);
            appResult.setCode(200);
            appResult.setMsg("更新告警提醒成功");
            appResult.setData(data);
        } else {
            data.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("更新告警提醒失败");
            appResult.setData(data);
        }
        return appResult;
    }

    @MyPower(name = "存入缓存", url = "/putRedis", isPublic = true)
    @ResponseBody
    @RequestMapping("putRedis")
    public AppResult putRedis(String id, String value) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        redisTemplateX.set(id, value, ConstantUtil.USER_TOKEN_EXPIRE);
        data.put("value", id);
        appResult.setCode(200);
        appResult.setMsg("存入缓存成功");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "取出缓存的值", url = "/getRedis", isPublic = true)
    @ResponseBody
    @RequestMapping("getRedis")
    public AppResult getRedis(String id) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        data.put("value", redisTemplateX.get(id));
        appResult.setCode(200);
        appResult.setMsg("取出缓存的值成功");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "11111111111111", url = "/grtAssessment", isPublic = true)
    @ResponseBody
    @RequestMapping("grtAssessment")
    public AppResult grtAssessment(String unitCode, String date, String registTime) {
        AppResult result = new AppResult();
        platformService.grtAssessment(unitCode, date, registTime);
        result.setCode(200);
        result.setMsg("根据单位编号查询卷宗出入库统计成功!");
        return result;
    }

    @MyPower(name = "执法考核统计", url = "/selectExaminationStatistics", isPublic = true)
    @ResponseBody
    @RequestMapping("selectExaminationStatistics")
    public AppResult selectExaminationStatistics(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        int pageNum = queryCondition.getIntValue("pageNum");
        int pageSize = queryCondition.getIntValue("pageSize");
        Examination examination = new Examination();
        examination.setQueryCondition(queryCondition);
        examination.setPage(pageNum, pageSize);
        if (StringUtil.isEmpty(examination.getUnitCodes())) {
            data.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(data);
            return appResult;
        }
        //获取本单位及子单位所有单位编号
        //List<OrganizationVo> list = platformService.findUnitInfoByUnitCodeS(examination.getUnitCodes());
//        List<String> strList = new ArrayList<>();
//        for (OrganizationVo vo : list) {
//            strList.add(vo.getHandleUnitCode());
//        }
//        String str1 = "";
//        for (int i = 0; i < strList.size(); i++) {
//            str1 += strList.get(i) + ",";
//        }
        // examination.setUnitCodes(str1);
        List<Examination> orderList = platformService.selectExaminationStatistics(examination);
        PageInfo<Examination> pageInfo = new PageInfo<>(orderList);
        // 查询是否有子单位
        pageInfo.getList().stream().forEach(item -> {
            item.setIsHaveChildUnit(unitService.findChildUnitNumById(item.getId()));
        });
        DataGrid dataGrid = new DataGrid(pageInfo.getTotal(), pageInfo.getList());
        data.put("datagrid", dataGrid);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "执法考核统计导出", url = "/ExaminationInfoReport", isPublic = true)
    @CrossOrigin
    @RequestMapping("ExaminationInfoReport")
    public void ExaminationInfoReport(@RequestBody Examination examination, HttpServletResponse response) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
//        List<OrganizationVo> list = platformService.findUnitInfoByUnitCodeS(examination.getUnitCodes());
//        List<String> strList = new ArrayList<>();
//        for (OrganizationVo vo : list) {
//            strList.add(vo.getHandleUnitCode());
//        }
//        String str1 = "";
//        for (int i = 0; i < strList.size(); i++) {
//            str1 += strList.get(i) + ",";
//        }
//        examination.setUnitCodes(str1);
//        String str=platformService.ExaminationInfoReport(examination,response);
        platformService.ExaminationInfoReport(examination, response);
//        data.put("datagrid", str);
//        appResult.setCode(200);
//        appResult.setMsg("query success");
//        appResult.setData(data);
//        return appResult;

    }

    @MyPower(name = "查询视频类型统计", url = "/selectVideoByUnitCode", isPublic = true)
    @ResponseBody
    @RequestMapping("selectVideoByUnitCode")
    public AppResult selectVideoByUnitCode(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();

        Map<String, Object> map = platformService.selectVideoByUnitCode(queryCondition);
        data.put("datagrid", map);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    //暂时不用了
    @MyPower(name = "查询案件类型统计", url = "/selectCaseTypeSum", isPublic = true)
    @ResponseBody
    @RequestMapping("selectCaseTypeSum")
    public AppResult selectCaseTypeSum(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();

        Map<String, Object> map = platformService.selectCaseTypeSum(queryCondition);
        data.put("datagrid", map);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "卷宗流转统计", url = "/selectFileTransferSum", isPublic = true)
    @ResponseBody
    @RequestMapping("selectFileTransferSum")
    public AppResult selectFileTransferSum(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();

        Map<String, Object> map = platformService.selectFileTransferSum(queryCondition);
        data.put("datagrid", map);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    @MyPower(name = "查询地图数据案件总数统计", url = "/selectMapCaseSum", isPublic = true)
    @RequestMapping("selectMapCaseSum")
    public AppResult selectMapCaseSum(@RequestBody JSONObject queryCondition) {
        JSONObject data = new JSONObject();

//        Map<String, Object> map = platformService.selectMapCaseSum(queryCondition);
        List<Map<String, Object>> list = platformService.selectMapCaseSums(queryCondition);
        data.put("list", list);
        return AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg(ResultEnum.SUCCESS.getMsg()).setData(data);
    }

    @MyPower(name = "查询案情信息統計", url = "/selectStatementCaseSum", isPublic = true)
    @ResponseBody
    @RequestMapping("selectStatementCaseSum")
    public AppResult selectStatementCaseSum(@RequestBody JSONObject queryCondition) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();

        Map<String, Object> map = platformService.selectStatementCaseSum(queryCondition);
        data.put("datagrid", map);
        appResult.setCode(200);
        appResult.setMsg("query success");
        appResult.setData(data);
        return appResult;
    }

    /**
     * @param handleUnitCode 单位编号逗号分隔
     * @return
     */
    @MyPower(name = "新版根据单位编号查询已完成案件数", url = "/findPassCaseByUnitCode")
    @ResponseBody
    @RequestMapping("findPassCaseByUnitCode")
    public AppResult findPassCaseByUnitCode(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(data);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(handleUnitCode)) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(handleUnitCode);
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }

            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");

            }
        }
        Map<String, Object> caseStatus = platformService.findPassCaseByUnitCode(array);
        data.put("title", caseStatus == null ? null : caseStatus.get("title"));
        data.put("value", caseStatus == null ? null : caseStatus.get("value"));
        result.setCode(200);
        result.setMsg("根据单位编号查询审核完成案件数成功!");
        result.setData(data);
        return result;
    }

    // @PostConstruct
    // public void getTableName() {
//        List<String> list = inquestionsMapper.getTableName();
//        System.out.println(list + "=====================================================1111111111111111111111111111111111111");
//        for (String str : list) {
//            System.out.println(str + "表名字++++++++++++++++++++++++++++++++++++++++++++++++");
//            aaa(str);
//        }

//    @PostConstruct
//    public void ge
//    tTableName() {
////        List<String> list = inquestionsMapper.getTableName();
////        System.out.println(list + "=====================================================1111111111111111111111111111111111111");
////        for (String str : list) {
////            System.out.println(str + "表名字++++++++++++++++++++++++++++++++++++++++++++++++");
////            aaa(str);
////        }
////
//        System.out.println(" ping start:");//执行开始
//        Connection conn = null;
//        String sql;
//        String url = "jdbc:oracle:thin:@59.204.92.240:1521:orcl";
//        /*指定数据的用户名和密码*/
//        String username = "sthydata";
//        String password = "santaiheyi";
//        try {
//
//            Class.forName("oracle.jdbc.driver.OracleDriver");
//
//            conn = DriverManager.getConnection(url, username, password);
//            Statement stmt = conn.createStatement();
//
//            //查询oracle中的所有表名称
//            //List<String> list=inquestionsMapper.getTableName();
//            sql = "select TABLE_NAME from all_tab_comments where owner='STHYDATA'";
//            ResultSet result = stmt.executeQuery(sql);
//            List<String> list = new ArrayList<>();
//            while (result.next()) {
//                list.add(result.getString("TABLE_NAME"));
//            }
//            for (String str : list) {
//                aaa(str,stmt);
//                System.out.println(str + "表名字++++++++++++++++++++++++++++++++++++++++++++++++");
//            }
//            System.exit(0);
//            System.out.println(" ping end: ");//执行结束
//        } catch (Exception e) {
//            System.out.println("第一个方法错误");
//        }finally {
//            try {
//                if (conn != null) {
//                    conn.close();
//                }
//            }catch (Exception e){
//                System.out.println("连接释放异常");
//            }
//        }
//    }

    //将oracle中的表数据导出成txt文件
//    public void aaa(String tableName,Statement stmt) {
//        Connection conn = null;
//        String sql;
//        String url = "jdbc:oracle:thin:@59.204.92.240:1521:orcl";
//        /*指定数据的用户名和密码*/
//        String username = "sthydata";
//        String password = "santaiheyi";
//        try {
//
//            //查询oracle中的所有表名称
//            //List<String> list=inquestionsMapper.getTableName();
//            Date d1 = new Date();
//            long str1 = d1.getTime();
//            System.out.println(d1);
//            //通过表名称查询其中的数据
//            sql = "select * from STHYDATA.\"" + tableName + "\"";
//            ResultSet rs = stmt.executeQuery(sql);// executeUpdate语句会返回一个受影响的行数，如果返回-1就没有成功
//            System.out.println(rs + "------------------------------------");
//            //求表中记录的列数
//            ResultSetMetaData rsmd = null;
//            rsmd = rs.getMetaData();
//            int n = rsmd.getColumnCount();//获得查询结果的列数
//            System.out.println("列数＝" + n);
//            //FileOutputStream fos = new FileOutputStream("E:\\" + tableName + ".txt", true);
//            FileOutputStream fos = new FileOutputStream(ConstantUtil.TXT_PATH + tableName + ".txt", true);
//            //fos.write(rs.getInt(1));
//            PrintStream p = new PrintStream(fos);
////            while (rs.next()) {
////                String strs = "";
////                for (int i = 1; i <=n; i++) {
////                    //String get = rs+".getString("+i+")+ \",\" +";
////                    String get = rs.getString(i)+ ",";
////                    strs +=get;
////                    String b1 = strs.substring(0, strs.lastIndexOf(")")+1)+";";
////                }
////                String sb = strs;
////                //FileOutputStream fos = new FileOutputStream("E:\\ok.txt",true);
////                //fos.write(rs.getInt(1));
////                //PrintStream p = new PrintStream(fos);
////                p.println(sb);
////            }
//            while (rs.next()) {
//                String strs = "";
//                for (int i = 1; i <= n; i++) {
//                    //String get = rs+".getString("+i+")+ \",\" +";
//                    strs += "/,/" + (StringUtil.isEmpty(rs.getString(i)) ? "" : rs.getString(i).replace(" ","").replaceAll("\n|\t|\r|", ""));
//                    //strs += "," + rs.getString(i);
//                }
//                String sb = strs.substring(3);
//                //FileOutputStream fos = new FileOutputStream("E:\\ok.txt",true);
//                //fos.write(rs.getInt(1));
//                //PrintStream p = new PrintStream(fos);
//                p.println(sb);
//            }
//
//            p.close();
//            fos.flush();
//            Date d2 = new Date();
//            long str2 = d2.getTime();
//            System.out.println(str2 - str1 + "==============================================================");
//        } catch (Exception e) {
//            System.out.println("aaa方法中报错");
//        }finally {
//            try {
//                if (conn != null) {
//                    conn.close();
//                }
//            }catch (Exception e){
//                System.out.println("连接释放异常");
//            }
//        }
//
//    }

    //    }
    // @PostConstruct
    public void getTableName() {
        System.out.println(" ping start:");//执行开始
        Connection conn = null;
        String sql;
        String url = "jdbc:oracle:thin:@59.204.92.240:1521:orcl";
        /*指定数据的用户名和密码*/
        String username = "sthydata";
        String password = "santaiheyi";
        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

            conn = DriverManager.getConnection(url, username, password);
            Statement stmt = conn.createStatement();

            //查询oracle中的所有表名称
            sql = "select TABLE_NAME from all_tab_comments where owner='STHYDATA'";
            ResultSet result = stmt.executeQuery(sql);
            List<String> list = new ArrayList<>();
            while (result.next()) {
                list.add(result.getString("TABLE_NAME"));
            }
            for (String str : list) {
                aaa(str, stmt);
                System.out.println(str + "表名字++++++++++++++++++++++++++++++++++++++++++++++++");
            }
            System.exit(0);
            System.out.println(" ping end: ");//执行结束
        } catch (Exception e) {
            System.out.println("第一个方法错误");
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e) {
                System.out.println("连接释放异常");
            }
        }
    }

    //将oracle中的表数据导出成txt文件
    public void aaa(String tableName, Statement stmt) {
        Connection conn = null;
        String sql;
        String url = "jdbc:oracle:thin:@59.204.92.240:1521:orcl";
        /*指定数据的用户名和密码*/
        String username = "sthydata";
        String password = "santaiheyi";
        try {
            //查询oracle中的所有表名称
            Date d1 = new Date();
            long str1 = d1.getTime();
            System.out.println(d1);
            //通过表名称查询其中的数据
            sql = "select * from STHYDATA.\"" + tableName + "\"";
            ResultSet rs = stmt.executeQuery(sql);// executeUpdate语句会返回一个受影响的行数，如果返回-1就没有成功
            System.out.println(rs + "------------------------------------");
            //求表中记录的列数
            ResultSetMetaData rsmd = null;
            rsmd = rs.getMetaData();
            int n = rsmd.getColumnCount();//获得查询结果的列数
            System.out.println("列数＝" + n);
            FileOutputStream fos = new FileOutputStream(ConstantUtil.TXT_PATH + tableName + ".txt", true);
            PrintStream p = new PrintStream(fos);
            boolean convertSuccess = true;
            SimpleDateFormat format = new SimpleDateFormat(DateUtil.DATE_FORMAT_MINUS);
            format.setLenient(false);

            while (rs.next()) {
                String strs = "";
                String st = "";
                for (int i = 1; i <= n; i++) {
                    if (!StringUtil.isEmpty(rs.getString(i))) {
                        if (PolicePlatformController.isValidDate(rs.getString(i))) {
                            st = rs.getString(i).replaceAll("\n|\t|\r|", "");
                        } else {
                            st = rs.getString(i).replace(" ", "").replaceAll("\n|\t|\r|", "");
                        }
                    } else {
                        st = "";
                    }
                    strs += "/,/" + st;

                }
                String sb = strs.substring(3);
                p.println(sb);
            }

            p.close();
            fos.flush();
            Date d2 = new Date();
            long str2 = d2.getTime();
            System.out.println(str2 - str1 + "==============================================================");
        } catch (Exception e) {
            System.out.println("aaa方法中报错");
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e) {
                System.out.println("连接释放异常");
            }
        }

    }

    public static boolean isValidDate(String str) {
        boolean convertSuccess = true;
        // 指定日期格式为四位年/两位月份/两位日期，注意yyyy/MM/dd区分大小写；
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期，比如2007/02/29会被接受，并转换成2007/03/01
            format.setLenient(false);
            format.parse(str);
        } catch (ParseException e) {
            // e.printStackTrace();
            // 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
            convertSuccess = false;
        }
        return convertSuccess;
    }

    /**
     * 三合一平台查询案件下的录音
     *
     * @param unitInfo
     * @return
     */
    @MyPower(name = "三合一平台查询案件下的录音", url = "/selectRecordInfol", isPublic = true)
    @ResponseBody
    @RequestMapping("selectRecordInfol")
    public AppResult selectRecordInfol(RecordInfo recordInfo) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(recordInfo.getSCaseId())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        List<RecordInfo> vo = platformService.selectRecordInfol(recordInfo);
        date.put("vo", vo);
        appResult.setCode(200);
        appResult.setMsg("三合一平台查询案件下的录音成功");
        appResult.setData(date);
        return appResult;
    }

    @MyPower(name = "更新音频关联状态", url = "/updateRecordInfo", isPublic = true)
    @ResponseBody
    @RequestMapping("updateRecordInfo")
    public AppResult updateRecordInfo(@RequestBody RecordInfo recordInfo) {
        AppResult appResult = new AppResult();
        JSONObject data = new JSONObject();
        //int value = platformService.updateRecordInfo(recordInfo);
        // 二级文件夹信息
        MaterialTypeDocument document = materialTypeDocumentService.findDocumentById(recordInfo.getDocumentid());
        MaterialType mt;
        if (document == null) {
            data.put("value", "未查询到文件夹信息！");
            return AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("添加警告！").setData(data);
        } else {
            // 一级目录信息
            mt = materialTypeService.findById(document.getMaterialtypeid());
        }
        System.out.println(recordInfo + "=============================================");
        // 文件存放路径==》 案件名称-警员id-案件编号/嫌疑人姓名/一级目录名称/二级文件夹名称/
        String rootpath = mt.getCasename() + "-" + mt.getUploadpoliceid() + "-" + mt.getCasecode() + File.separator
                + mt.getCaseSuspectName() + File.separator + mt.getMaterialtypename() + File.separator
                + document.getDocumentname();

        // 设置存放图片文件的路径
        String fileDocPath = rootpath + File.separator;

        if (ConstantUtil.XSKYRESTORAGE) {
            // 源文件在xsky,复制到桶下的文件夹
            if (recordInfo.getUploadType().equals("1")) {
                int M = 0;
                if (platformService.updateRecordInfo(M, recordInfo.getId(), recordInfo.getDocumentid(), fileDocPath, recordInfo.getSPath()) > 0) {
                    appResult = AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("文件上传成功！");
                } else {
                    appResult = AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("文件上传失败！(可能原因：1.上传文件为空；2.xsky上传失败)");
                }
                // 源文件在服务器，复制到桶下的文件夹
            }
            if (recordInfo.getUploadType().equals("0")) {
                int M = 1;
                if (platformService.updateRecordInfo(M, recordInfo.getId(), recordInfo.getDocumentid(), fileDocPath, recordInfo.getSPath()) > 0) {
                    appResult = AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("文件上传成功！");
                } else {
                    appResult = AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("文件上传失败！(可能原因：1.上传文件为空；2.xsky上传失败)");
                }
            }
        } else {
            // 源文件在xsky
            if (recordInfo.getUploadType().equals("1")) {
                int M = 0;
                if (platformService.updateInfoOnServer(M, recordInfo.getId(), recordInfo.getDocumentid(), fileDocPath, recordInfo.getSPath()) > 0) {
                    appResult = AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("文件上传成功！");
                } else {
                    appResult = AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("文件上传失败！(可能原因：1.上传文件为空；2.xsky上传失败)");
                }
                // 源文件在服务器
            }
            if (recordInfo.getUploadType().equals("0")) {
                int M = 1;
                if (platformService.updateInfoOnServer(M, recordInfo.getId(), recordInfo.getDocumentid(), fileDocPath, recordInfo.getSPath()) > 0) {
                    appResult = AppResult.builder().setCode(ResultEnum.SUCCESS.getCode()).setMsg("文件上传成功！");
                } else {
                    appResult = AppResult.builder().setCode(ResultEnum.FAIL.getCode()).setMsg("文件上传失败！(可能原因：1.上传文件为空；2.xsky上传失败)");
                }
            }
        }

        return appResult;
    }

    /**
     * 三合一110/119/122报警占比比例
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "三合一110/119/122报警占比比例", url = "/selectCallPolice", isPublic = true)
    @ResponseBody
    @RequestMapping("selectCallPolice")
    public AppResult selectCallPolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(handleUnitCode)) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(handleUnitCode);
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }

            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");

            }
        }
        Map map = platformService.selectCallPolice(array);
        date.put("map", map);
        result.setCode(200);
        result.setMsg("查询三合一110/119/122报警占比比例成功");
        result.setData(date);
        return result;
    }

    /**
     * 三合一警情占比比例
     *
     * @param handleUnitCode 单位编号
     * @return
     */

    @MyPower(name = "三合一警情占比比例", url = "/selectPoliceSituation", isPublic = true)
    @RequestMapping("selectPoliceSituation")
    public AppResult selectPoliceSituation(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }

        Map<String, Object> map = platformService.selectPoliceSituation(handleUnitCode);
        redisTemplateX.set("selectPoliceSituation" + handleUnitCode, map);
        date.put("map", map);
        result.setCode(200);
        result.setMsg("查询三合一警情占比比例成功");
        result.setData(date);
        return result;
    }

    /**
     * 三合一警情占比比例
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "取缓存警情数据", url = "/returnRedisPoliceSituation", isPublic = true)
    @RequestMapping("returnRedisPoliceSituation")
    public AppResult returnRedisPoliceSituation(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        date.put("map", redisTemplateX.get("selectPoliceSituation" + handleUnitCode));
        result.setCode(200);
        result.setMsg("查询三合一警情占比比例成功");
        result.setData(date);
        return result;
    }

    /**
     * 三合一警情今年总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "取缓存警情今年总数", url = "/returnRedisPoliceSituationCount", isPublic = true)
    @RequestMapping("returnRedisPoliceSituationCount")
    public AppResult returnRedisPoliceSituationCount(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        Map<String, Object> map = new HashMap();
        int countForCJPolice = (int) redisTemplateX.get("countForCJPolice" + handleUnitCode);
        //接警
        Map<String, Object> receiveMap = (Map<String, Object>) redisTemplateX.get("countForReceiveThePolice" + handleUnitCode);
        int countForReceiveThePolice = (int) receiveMap.get("countForReceiveThePolice");
        int countForReceive_110 = (int) receiveMap.get("countForReceive_110");
        int countForReceive_119 = (int) receiveMap.get("countForReceive_119");
        int countForReceive_122 = (int) receiveMap.get("countForReceive_122");
        int countForEffectivePolice = (int) redisTemplateX.get("countForEffectivePolice" + handleUnitCode);
        int countForInvalidPolice = (int) redisTemplateX.get("countForInvalidPolice" + handleUnitCode);
        int countForBigPolice = (int) redisTemplateX.get("countForBigPolice" + handleUnitCode);
        int countForOutPolice = (int) redisTemplateX.get("countForOutPolice" + handleUnitCode);

        map.put("countForCJPolice", countForCJPolice);
        map.put("countForReceiveThePolice", countForReceiveThePolice);
        map.put("countForEffectivePolice", countForEffectivePolice);
        map.put("countForInvalidPolice", countForInvalidPolice);
        map.put("countForBigPolice", countForBigPolice);
        map.put("countForOutPolice", countForOutPolice);
        int count = platformService.selectPoliceSituationCountByCode(handleUnitCode);
        if (count < 1) {
            PoliceSituationMiddle policeSituationMiddle = new PoliceSituationMiddle();
            policeSituationMiddle.setHandleUnitCode(handleUnitCode);
            policeSituationMiddle.setCjCount(countForCJPolice);
            policeSituationMiddle.setReceiveCount(countForReceiveThePolice);
            policeSituationMiddle.setEffectiveCount(countForEffectivePolice);
            policeSituationMiddle.setInvalidCount(countForInvalidPolice);
            policeSituationMiddle.setBigCount(countForBigPolice);
            policeSituationMiddle.setOutCount(countForOutPolice);
            policeSituationMiddle.setReceive110(countForReceive_110);
            policeSituationMiddle.setReceive119(countForReceive_119);
            policeSituationMiddle.setReceive122(countForReceive_122);
            platformService.addPoliceSituation(policeSituationMiddle);
        }

        date.put("map", map);
        result.setCode(200);
        result.setMsg("取缓存警情今年总数");
        result.setData(date);
        return result;
    }

    /**
     * 获取警情处警总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取警情处警总数", url = "/countForCJPolice", isPublic = true)
    @RequestMapping("countForCJPolice")
    public AppResult countForCJPolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        int count = platformService.countForCJPolice(handleUnitCode);
        redisTemplateX.set("countForCJPolice" + handleUnitCode, count);
        date.put("data", count);
        result.setCode(200);
        result.setMsg("查询警情处警总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 获取有效警情总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取有效警情总数", url = "/countForEffectivePolice", isPublic = true)
    @RequestMapping("countForEffectivePolice")
    public AppResult countForEffectivePolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        int count = platformService.countForEffectivePolice(handleUnitCode);
        redisTemplateX.set("countForEffectivePolice" + handleUnitCode, count);
        date.put("data", count);
        result.setCode(200);
        result.setMsg("查询有效警情总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 获取接警事件总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取接警事件总数", url = "/countForReceiveThePolice", isPublic = true)
    @RequestMapping("countForReceiveThePolice")
    public AppResult countForReceiveThePolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        Map<String, Object> map = platformService.countForReceiveThePolice(handleUnitCode);
        redisTemplateX.set("countForReceiveThePolice" + handleUnitCode, map);
        date.put("map", map);
        result.setCode(200);
        result.setMsg("查询接警事件总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 获取无效警情总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取无效警情总数", url = "/countForInvalidPolice", isPublic = true)
    @RequestMapping("countForInvalidPolice")
    public AppResult countForInvalidPolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        int count = platformService.countForInvalidPolice(handleUnitCode);
        redisTemplateX.set("countForInvalidPolice" + handleUnitCode, count);
        date.put("data", count);
        result.setCode(200);
        result.setMsg("查询无效警情总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 获取重大警情总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取重大警情总数", url = "/countForBigPolice", isPublic = true)
    @RequestMapping("countForBigPolice")
    public AppResult countForBigPolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        int count = platformService.countForBigPolice(handleUnitCode);
        redisTemplateX.set("countForBigPolice" + handleUnitCode, count);
        date.put("data", count);
        result.setCode(200);
        result.setMsg("查询重大警情总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 获取涉外警情总数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "获取涉外警情总数", url = "/countForOutPolice", isPublic = true)
    @RequestMapping("countForOutPolice")
    public AppResult countForOutPolice(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            result.setCode(-1);
            result.setMsg("没有传入参数");
            result.setData(date);
            return result;
        }
        int count = platformService.countForOutPolice(handleUnitCode);
        redisTemplateX.set("countForOutPolice" + handleUnitCode, count);
        date.put("data", count);
        result.setCode(200);
        result.setMsg("查询涉外警情总数成功");
        result.setData(date);
        return result;
    }

    /**
     * 监督中心警情统计二级页面详情列表
     */
    @MyPower(name = "监督中心警情统计二级页面详情列表", url = "/selectPoliceDetails", isPublic = true)
    @ResponseBody
    @RequestMapping("selectPoliceDetails")
    public AppResult selectPoliceDetails(@RequestBody CallPoliceProportion callPoliceProportion) {
        AppResult appResult = new AppResult();
        JSONObject date = new JSONObject();
        if (StringUtil.isEmpty(callPoliceProportion.getUnitCodes())) {
            date.put("value", 0);
            appResult.setCode(-1);
            appResult.setMsg("参数为空");
            appResult.setData(date);
            return appResult;
        }
        List<CallPoliceProportion> list = platformService.selectPoliceDetails(callPoliceProportion);
        date.put("list", list);
        appResult.setCode(200);
        appResult.setMsg("监督中心警情统计二级页面详情列表成功");
        appResult.setData(date);
        return appResult;
    }

    /**
     * 监督中心警情统计二级页面根据单位编号查询警情详情列表
     */
    @MyPower(name = "监督中心警情统计二级页面根据单位编号查询警情详情列表", url = "/selectPoliceSituationByUnicode", isPublic = true)
    @ResponseBody
    @RequestMapping("selectPoliceSituationByUnicode")
    public AppResult selectPoliceSituationByUnicode(@RequestBody PoliceSituationVo vo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        List<PoliceSituationVo> orderList = platformService.selectPoliceSituationByUnicode(vo);
        //用PageInfo对结果进行包装selectStatistics
        PageInfo<PoliceSituationVo> pageInfo = new PageInfo<PoliceSituationVo>(orderList);
        DataGrid dataGrid = new DataGrid(pageInfo.getTotal(), pageInfo.getList());
        data.put("datagrid", dataGrid);
        result.setCode(200);
        result.setMsg("查询成功");
        result.setData(data);
        return result;
    }

    /**
     * 监督中心案件类型统计及查看更多（饼图）
     * unitCodes前台传单位字符串
     */
    @MyPower(name = "监督中心案件类型统计", url = "/selectStatistics", isPublic = true)
    @ResponseBody
    @RequestMapping("selectStatistics")
    public AppResult selectStatistics(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if ("0".equals(unitInfo.getType())) {
            String str1 = "";
            String array[] = null;
            if (!StringUtil.isEmpty(unitInfo.getUnitCode())) {
                List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(unitInfo.getUnitCode());
                List<String> strList = new ArrayList<>();
                for (OrganizationVo vo : lists) {
                    strList.add(vo.getHandleUnitCode());
                }

                for (int i = 0; i < strList.size(); i++) {
                    str1 += strList.get(i) + ",";
                    // examination.setUnitCodes(str1);
                    //String unicodes=dossierRecordVo.getUnitcodes();
                    array = str1.split(",");

                }
            }
            unitInfo.setArray(array);
        }
        if ("1".equals(unitInfo.getType())) {
            String[] array = unitInfo.getUnitCodes().split(",");
            unitInfo.setArray(array);
            //unitInfo.setArray(array);
        }
        log.info("user query...");
        Map<String, Object> map = platformService.selectStatistics(unitInfo);
        data.put("map", map);
        result.setCode(200);
        result.setMsg("query success");
        result.setData(data);
        return result;
    }

    /**
     * 监督中心刑事案件排名
     */
    @MyPower(name = "监督中心刑事案件排名", url = "/selectCriminalCase", isPublic = true)
    @ResponseBody
    @RequestMapping("selectCriminalCase")
    public AppResult selectCriminalCase(String handleUnitCode) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(handleUnitCode)) {
            data.put("value", 0);
            result.setCode(-1);
            result.setMsg("单位参数为空");
            result.setData(data);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(handleUnitCode)) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(handleUnitCode);
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }

            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");

            }
        }
        List<Map<String, Object>> list = platformService.selectCriminalCase(array);
        data.put("list", list);
        result.setCode(200);
        result.setMsg("查询监督中心刑事案件排名成功");
        result.setData(data);
        return result;
    }

    /**
     * 案件细类统计刑事，政治，民事案件统计
     */
    @MyPower(name = "案件细类统计刑事，政治，民事案件统计", url = "/selectStatisticsSort", isPublic = true)
    @ResponseBody
    @RequestMapping("selectStatisticsSort")
    public AppResult selectStatisticsSort(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCode())) {
            data.put("value", 0);
            result.setCode(-1);
            result.setMsg("参数为空");
            result.setData(data);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(unitInfo.getUnitCode())) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(unitInfo.getUnitCode());
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }

            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");

            }
        }
        unitInfo.setArray(array);
        List<Map<String, Object>> list = platformService.selectStatisticsSort(unitInfo);
        data.put("list", list);
        result.setCode(200);
        result.setMsg("案件细类统计刑事，政治，民事案件统计");
        result.setData(data);
        return result;
    }

    /**
     * 案件细类统计刑事案件下拉框列表32种细类数据
     */
    @MyPower(name = "案件细类统计刑事案件下拉框列表32种细类数据", url = "/selectCriminalCaseSort", isPublic = true)
    @ResponseBody
    @RequestMapping("selectCriminalCaseSort")
    public AppResult selectCriminalCaseSort(@RequestBody UnitInfo unitInfo) {
        AppResult result = new AppResult();
        JSONObject data = new JSONObject();
        if (StringUtil.isEmpty(unitInfo.getUnitCode())) {
            data.put("value", 0);
            result.setCode(-1);
            result.setMsg("参数为空");
            result.setData(data);
            return result;
        }
        String str1 = "";
        String array[] = null;
        if (!StringUtil.isEmpty(unitInfo.getUnitCode())) {
            List<OrganizationVo> lists = platformService.findUnitInfoByUnitCodeS(unitInfo.getUnitCode());
            List<String> strList = new ArrayList<>();
            for (OrganizationVo vo : lists) {
                strList.add(vo.getHandleUnitCode());
            }

            for (int i = 0; i < strList.size(); i++) {
                str1 += strList.get(i) + ",";
                // examination.setUnitCodes(str1);
                //String unicodes=dossierRecordVo.getUnitcodes();
                array = str1.split(",");

            }
        }
        unitInfo.setArray(array);
        List<Organization> list = platformService.selectCriminalCaseSort(unitInfo);
        data.put("list", list);
        result.setCode(200);
        result.setMsg("案件细类统计刑事案件下拉框列表32种细类数据");
        result.setData(data);
        return result;
    }

    /**
     * 查询总注册人数和在线人数
     *
     * @param handleUnitCode 单位编号
     * @return
     */
    @MyPower(name = "查询总注册人数和在线人数", url = "/selectOnlinePoliceCount", isPublic = true)
    @RequestMapping("selectOnlinePoliceCount")
    public AppResult selectOnlinePoliceCount() {
        AppResult result = new AppResult();
        JSONObject date = new JSONObject();
        Map<String, Object> map = new HashMap();
        Set<String> keys = redisTemplateX.keys("*" + RedisKey.POWER_LIST);
        System.out.println("=======在线人数=======" + keys);
        int count = platformService.selectOnlinePoliceCount();
        map.put("total", count);
        map.put("online", keys.size());
        date.put("map", map);
        result.setCode(200);
        result.setMsg("查询总注册人数和在线人数");
        result.setData(date);
        return result;
    }

    /**
     * 警综人员查询接口
     *
     * @param GMSFHM 身份证号码
     * @return
     * @throws Exception
     */
    @MyPower(name = "警综人员查询接口", url = "/selectJZPersonInfo", isPublic = true)
    @RequestMapping("selectJZPersonInfo")
    public JSONObject selectJZPersonInfo(String GMSFHM) throws Exception {
        String url = "http://10.72.36.27:3016/gateway/rest/invoke";
        Header[] headers = {
                new BasicHeader("IDCardNo", "422823197804172431")
//                , new BasicHeader("instanceId", "BCD44AD1390172DD6360F641335727CC")
                , new BasicHeader("instanceId", "136B09382C527183676B2793A3A9A20D")
                , new BasicHeader("orgCode", "422800000000")
                , new BasicHeader("serviceId", "CE34E2282C1BFA8D5E5F3D1FF6E21DD9")
//                , new BasicHeader("Content-Type", "application/json")
                , new BasicHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())
        };
        Map<String, String> paramMap = new HashMap<>();
//        paramMap.put("GMSFHM", GMSFHM);
        paramMap.put("gmsfhm", GMSFHM);
        String s = doPost(url, paramMap, headers, null);
        return JSONObject.parseObject(s);
    }


    public String doPost(String uri, Map<String, String> params, Header[] header, String charset) throws Exception {
        CloseableHttpClient client = HttpClients.createDefault();
        //定义post提交方式
        HttpPost httpPost = new HttpPost(uri);
        if (StringUtils.isEmpty(charset)) {
            charset = "utf-8";
        }
        //设置请求参数
        log.info("=======" + JSONObject.toJSONString(params));
        //使用json格式来设置body使用StringEntity类
        StringEntity se = new StringEntity(JSONObject.toJSONString(params), "UTF-8");
        httpPost.setEntity(se);
        httpPost.setHeaders(header);
        HttpResponse httpResponse = client.execute(httpPost);
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            String result = EntityUtils.toString(httpResponse.getEntity(), charset);
            return result;
        }
        return null;
    }

}
